home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_10_04 / 1004046a < prev    next >
Text File  |  1992-02-11  |  29KB  |  625 lines

  1. /* 
  2. menu =  controls cursor movement and menu display and selection -
  3.         returns the number of the selected menu item.              
  4.  
  5.         values:                 a string consisting of two digits showing
  6.                                 the number of menu choices, followed by  
  7.                                 four digits for each choice, the first   
  8.                                 two showing the starting column of the  
  9.                                 menu item and the second two its length. 
  10.                                                                         
  11.         menu_first_line:        the first line of instructions in the    
  12.                                 menu mode.                               
  13.                                                                         
  14.         menu_second_line:       the second line in the menu mode. It con-
  15.                                 tains the menu choices.                  
  16.                                                                         
  17.         screen_first_line:      the first line of instructions in the   
  18.                                 screen mode.                             
  19.                                                                         
  20.         screen_second_line:     the second line of instructions in the   
  21.                                 screen mode.                             
  22.                                                                         
  23.         menu_type:              0: Start with Menu Mode.                 
  24.                                    Alphanumeric characters are ignored   
  25.                                    when entered in screen mode.          
  26.                                 1: Start with Menu Mode.                 
  27.                                    Alphanumeric characters are displayed
  28.                                    when entered in screen mode
  29.                                 2: Start with Screen Mode.               
  30.                                    Alphanumeric characters are ignored   
  31.                                    when entered in screen mode.          
  32.                                 3: Start with Screen Mode.               
  33.                                    Alphanumeric characters are displayed 
  34.                                    when entered in screen mode.          
  35.                                                                         
  36.         screen_color:           color for screen mode.                   
  37.         menu_color:             color for menu display.
  38.                                                                         
  39.         highlight_color:        color of selected menu item              
  40.                                                                         
  41.         select_no:              number of menu items using selection     
  42.                                                                         
  43.         escape_char:            number of the key selected for escape    
  44.                                 from the screen display.                 
  45.                                                                         
  46.         map:                    bit map of permitted cursor locations.   
  47.                                 The cursor will go to permitted locations
  48.                                 only and no others.                      
  49. */
  50.  
  51. int menu(char values[],char menu_first_line[],char menu_second_line[],
  52.      char screen_first_line[],char screen_second_line[],int menu_type,
  53.      int screen_color,int menu_color,int highlight_color, int select_no,
  54.      int escape_char, int first_line_loc, char map[25][10])
  55. {
  56.         union REGS reg;
  57.         int i,choices,indx,start,length,menu_second_line_length;
  58.         int interim,remainder,temp;
  59.         char spaces[80],prev_char;
  60.  
  61.         for (i=0; i<76; i++)
  62.                 spaces[i] = ' ';
  63.         spaces[76] = '\0';
  64.         menu_second_line_length = strlen(menu_second_line);
  65.         gotoxy(2,first_line_loc);
  66.         choice = 1;
  67.         if (menu_type <= 1)
  68.         {
  69.                 color_printf("%s",menu_color,menu_first_line);
  70.                 gotoxy(2,first_line_loc+1);
  71.                 length = values[4] - '0';
  72.                 length = 10 * length + values[5] - '0';
  73.                 for (indx = 0; indx < menu_second_line_length; indx++)
  74.                         if (indx < length)
  75.                                 putcolorchar(menu_second_line[indx],
  76.                                         highlight_color);
  77.                         else
  78.                                 putcolorchar(menu_second_line[indx],
  79.                                         menu_color);
  80.         }
  81.         else
  82.         {
  83.                 color_printf(screen_first_line,menu_color);
  84.                 gotoxy(2,first_line_loc+1);
  85.                 color_printf(screen_second_line,menu_color);
  86.         }
  87.         choices = 10 * (values[0] - '0') + values[1] -'0';
  88.         gotoxy(column,row);
  89.         for(;;)
  90.         {
  91.                 key_id = getch();
  92.                 if (key_id == 0)
  93.                         key_id = getch()+256;
  94.                 if (menu_type <= 1)
  95.                 {
  96.                         switch(key_id)
  97.                         {
  98.                         case 13:
  99.                                 if(choice > select_no)
  100.                                         goto ExitPoint;
  101.                                 change_line_color(47);
  102.                                 gotoxy(2,23);
  103.                                 color_printf("%s",screen_color,spaces);
  104.                                 gotoxy(2,23);
  105.                                 color_printf("%s",menu_color,
  106.                                 screen_first_line);
  107.                                 gotoxy(2,24);
  108.                                 color_printf("%s",screen_color,spaces);
  109.                                 gotoxy(2,24);
  110.                                 color_printf("%s",menu_color,
  111.                                         screen_second_line);
  112.                                 gotoxy(column,row);
  113.                                 menu_type +=2;
  114.                                 break;
  115.                         case 333:    /*Right Arrow*/
  116.                                 choice = choice + 2;
  117.                         case 331:  /*Left Arrowb*/
  118.                                 --choice;
  119.                                 if (choice < 1)
  120.                                         choice = choices;
  121.                                 if (choice > choices)
  122.                                         choice = 1;
  123.                                 start = 10 * (values[(choice-1)*4+2] - '0')
  124.                                         +values[(choice-1)*4+3] - '0';
  125.                                 length = 10 * (values[(choice-1)*4+4] - '0')
  126.                                         +values[(choice-1)*4+5] - '0';
  127.                                 gotoxy(2,24);
  128.                                 for (indx = 0;indx < menu_second_line_length;
  129.                                         indx++)
  130.                                 {
  131.                                         if ((indx >= start) && (indx < start
  132.                                         + length))
  133.                                                 putcolorchar
  134.                                                         (menu_second_line
  135.                                                         [indx],
  136.                                                         highlight_color);
  137.                                         else
  138.                                                 putcolorchar
  139.                                                         (menu_second_line
  140.                                                         [indx],
  141.                                                         menu_color);
  142.                                 }
  143.                                 gotoxy(column,row);
  144.                                 break;
  145.                         default:
  146.                                 if ((key_id >= 0x41) && (key_id <= 0x7A))
  147.                                 {
  148.                                         temp = toupper(key_id);
  149.